package com.hr.dao;

import com.hr.model.Position;
import com.hr.model.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserDAO
{
    @Results(id = "user",value = {
            @Result(id = true, property = "id", column = "u_id"),
            @Result(property = "account", column = "u_account"),
            @Result(property = "password", column = "u_password"),
            @Result(property = "identity", column = "u_identity"),
            @Result(property = "archive", column = "u_id", one = @One(select = "com.hr.dao.ArchiveDAO.getArchiveByUId")),
    })
    @Select("select * from user where u_id=#{uid}")
    User getUserByUId(@Param("uid")int uid);

    @ResultMap("user")
    @Select("select * from user where u_account=#{acount}")
    User getUserByAccount(@Param("acount")String acount);

    @ResultMap("user")
    @Select("select * from user join user_wanted uw on user.u_id = uw.u_id where w_id=#{wid}")
    List<User> getUsersByWId(@Param("wid")int wid);

    @Update("update user set u_password=#{pw} where u_id=#{uid}")
    void updatePW(@Param("uid")int uid,@Param("pw")String pw);

    @Insert("insert into user (u_account, u_password, u_identity) VALUES (#{account},#{password},#{identity})")
    void insertUser(@Param("account")String account,@Param("password")String password,@Param("identity")String identity);
}
